<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>修改密码</title>
		[#include "/common/include.ftl"/]
		<link type="text/css" rel="styleSheet" href="${base}/resource/css/member.css">
		<script type="text/javascript" src="${base}/resource/js/member.js"></script>
		<script type="text/javascript" src="${base}/resource/js/encrypt.js"></script>
		<script type="text/javascript" src="${base}/resource/js/jquery.validate.js"></script>
		<script type="text/javascript" src="${base}/resource/js/password.js"></script>
		<script type="text/javascript" src="${base}/resource/js/validate.js"></script>
		<script type="text/javascript">
			$(function(){
				jQuery.validator.addMethod("passwordFM", function(value, element) {   
				    return this.optional(element) || checkPassword(value).success;       
				}, '密码长度为6-20，由英文、数字及符号中两种组成');
				var $validateForm = $("#modifyForm");
				$validateForm.validate({
					errorElement : 'span',
					errorClass : 'validError',
					rules: {
						"oldPwd": {
							required : true,
							passwordFM:true
						},
						"newPwd": {
							required: true,
							passwordFM:true
						},
						"repwd": {
							equalTo	: "#newPwd"
						}
					},
					messages: {
						"oldPwd": {
							required: "原始密码不正确",
							passwordFM:"原始密码不正确"
						},
						"newPwd": {
							required : "新密码不正确"
						},
						"repwd": {
							equalTo : "两次输入的密码不一致"
						}
					},
					errorPlacement : function(error, element){
						 error.appendTo(element.parent().find('.err-msg'));
					}
				});
				
				$("input").keydown(function(event){
					if(event.keyCode == 13){
						modify();
					}
				});
			});
			
			function modify(){
				if($("#modifyForm").valid()){
					var oldPwd = $("#oldPwd").val();
					var newPwd = $("#newPwd").val();
					ajax({
						url: base + "/publicKey.jhtml",
						type: "GET",
						cache: false,
						showError:true,
						loading:'正在登录...',
						success: function(data){
							var rsaKey = new RSAKey();
							rsaKey.setPublic(b64tohex(data.modulus), b64tohex(data.exponent));
							oldPwd = hex2b64(rsaKey.encrypt(oldPwd));
							newPwd = hex2b64(rsaKey.encrypt(newPwd));
							ajax({
								url	: base + "/member/modifyPwd.jhtml",
								data: {
									oldPwd 	: oldPwd,
									newPwd	: newPwd
								},
								showError:true,
								success	: function(data){
									oDialog.prompt("密码修改成功");
									$("#modifyForm")[0].reset();
								}
							});
						}
					});
				}
			}
		</script>
	</head>
	<body class="customer">
		[#include "/common/header.ftl"/]
		<div class="crumbs">
			<a href="${base}/member/index.jhtml">会员中心</a>
			<i style='font-family: simsun;font-style: normal;'>></i>
			<a>账户中心</a>
			<i style='font-family: simsun;font-style: normal;'>></i>
			<a>修改密码</a>
		</div>
		<div id="member-main">
			[#assign menuNo = 'password'/]
			[#include "/common/member-left.ftl"/]
			<div class="member-right">
				<div class="right-wrap">
					<h2 class="right-title">修改密码</h2>
					<div id="modify-pwd">
						<form id="modifyForm">
							<div id="form-groups-list">
								<dl class="item">
									<dt>
										原始密码
									</dt>
									<dd>
										<input type="password" name="oldPwd" id="oldPwd">
										<div class="err-msg"></div>
									</dd>
								</dl>
								<dl class="item">
									<dt>
										新密码
									</dt>
									<dd>
										<input type="password" name="newPwd" id="newPwd">
										<div class="err-msg"></div>
									</dd>
								</dl>
								<dl class="item">
									<dt>
										重复新密码
									</dt>
									<dd>
										<input type="password" name="repwd">
										<div class="err-msg"></div>
									</dd>
								</dl>
								<dl class="item">
									<dt></dt>
									<dd>
										<a class="hp-button hp-btn-modify" href="javascript:modify();">修改密码</a>
									</dd>
								</dl>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>
		[#include "common/footer-slidebar-lazyload.ftl"]
	</body>
</html>